home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / mergeCharacters.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  4.2 KB  |  144 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17.     //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Oct, 2000
  22. //  Author:         bb
  23. //
  24. //    Procedure Name:
  25. //        mergeCharacters
  26. //
  27. //    Description:
  28. //        Merge multiple characters into a single character. If multiple
  29. //        characters are selected and some of the characters are subcharacters
  30. //        of another of the characters, the subcharacters will be merged
  31. //        into the highest level character. If none of the characters are 
  32. //        subcharacters, the merge will be into the last selected character.
  33. //
  34. //    Input Arguments:
  35. //        none: works on the selection list
  36. //
  37. //    Return Value:
  38. //        name of the character that the other characters were merged to
  39. //
  40.  
  41. proc string[]
  42. findParentChar(string $chars[])
  43. //
  44. // Given a list of characters, recursively find those which are parents of
  45. // other characters in the list. Keep going til you find the most
  46. // parent characters of all.
  47. //
  48. {
  49.     int $charCount = size($chars);    
  50.     string $parentChar[];
  51.     int $ii, $jj; 
  52.     for ($ii = 0; $ii < $charCount; $ii++) {
  53.         $parentChar[$ii] = "";
  54.         for ($jj = 0; $jj < $charCount; $jj++) {
  55.             if ($ii == $jj) continue;
  56.             if (`character -isMember $chars[$jj] $chars[$ii]`) {
  57.                 $parentChar[$ii] = $chars[$jj];
  58.                 break;
  59.             }
  60.         }
  61.     }
  62.  
  63.     string $pc;
  64.     int $sizeCompressed = 0;
  65.     string $compressedParents[];
  66.     for ($ii = 0; $ii < $charCount; $ii++) {
  67.         if ("" != $parentChar[$ii]) {
  68.             $compressedParents[$sizeCompressed] = $parentChar[$ii];
  69.             $sizeCompressed++;
  70.         }
  71.     }
  72.  
  73.     // continue searching for parents until one or less is found
  74.     //
  75.     if (size($compressedParents) < 2) {
  76.         return $compressedParents;
  77.     } else {
  78.         string $newParents[];
  79.         $newParents = findParentChar($compressedParents);
  80.         if (size($newParents) == 0) {
  81.             return $compressedParents;
  82.         } else {
  83.             return $newParents;
  84.         }
  85.     }
  86. }
  87.  
  88. global proc string
  89. mergeCharacters()
  90. //    Description:
  91. //        Merge multiple characters into a single character. If multiple
  92. //        characters are selected and some of the characters are subcharacters
  93. //        of another of the characters, the subcharacters will be merged
  94. //        into the highest level character. If none of the characters are 
  95. //        subcharacters, the merge will be into the last selected character.
  96. //
  97. {
  98.     // Check for the proper selection -> two or more characters
  99.     //
  100.     string $chars[] = `ls -sl -type character`;
  101.     int $charCount = size($chars);
  102.     if ($charCount < 2) {
  103.         error("Select the characters to be merged.");
  104.         return "";
  105.     }
  106.  
  107.     // Find the character to merge to (highest character in hierarchy,
  108.     // or if there are no subcharacters, just use the last selected character)
  109.     //
  110.     string $mergeChar;
  111.     string $parentChars[] = findParentChar($chars);
  112.     if (size($parentChars)) {
  113.         $mergeChar = $parentChars[size($parentChars)-1];
  114.     } else {
  115.         $mergeChar = $chars[$charCount-1];
  116.     }
  117.  
  118.     string $character;
  119.     for ($character in $chars) {
  120.         if ($character == $mergeChar) continue;
  121.  
  122.         string $mem;
  123.         string $members[] = `character -q $character`;
  124.         string $attrs[];
  125.         clear $attrs;
  126.         for ($mem in $members) {
  127.             if (nodeType($mem) != "character") {
  128.                 $attrs[size($attrs)] = $mem;
  129.             }
  130.         }
  131.  
  132.         // transfer the attrs to the destination character
  133.         //
  134.         character -e -fe $mergeChar $members;
  135.  
  136.         // delete the source character
  137.         //
  138.         delete $character;
  139.     }
  140.  
  141.     
  142.     return $mergeChar;
  143. }
  144.